package service;

import dao.*;
import model.*;
import util.*;

public class RoomService {
	private static RoomService roomService=new RoomService();
	private RoomService() {}
	public static RoomService getInstance() {
		return roomService;
	}
	private RoomDao roomDao=RoomDao.getInstance();
	private RecordDao recordDao=RecordDao.getinstance();
	
	
	
	
	
	public void rentRoom(int uid,int rid,String rentTime,int judge) {
		Record record=new Record(uid,rid,rentTime,"未退房");
		if(judge>0) {
		roomDao.rentRoom(rid);
		recordDao.insertRecord(record);
		ShowMessage.show("办理入住成功");

		}else  {
			ShowMessage.show("房间已满不可租");
		}
		
		
}
	public void returnRoom(int uid,int rid,String returnTime) {
		if(recordDao.queryRecord(uid, rid)==null) {
			ShowMessage.show("退房失败!\n请确认该用户受否入住该房型");//先确认
		}else {
		int i=Integer.parseInt(returnTime)- 
				Integer.parseInt(recordDao.queryRecord(uid, rid).getRentTime());//计算隔离是否满14天
		if(i>14) {
			recordDao.updateRecord(uid, rid,returnTime); //应该加上rid防止退房时，防止多删同一个人的的其他方
				roomDao.returnRoom(rid);
				ShowMessage.show("隔离已达14天，退房成功");
				
		}else {
			ShowMessage.show("隔离未达14天，退房失败\n请继续于酒店接受隔离！");	
		}
	
		}
		}

}
